#include<bits/stdc++.h>
using namespace std;
int i,t,n,m,l,v,p[100001],mx;
struct node{
    int d,v,a;
}c[100001];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        mx=0;
        scanf("%d%d%d%d",&n,&m,&l,&v);
        bool flag=1;
        for(i=1;i<=n;i++){
            scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);

            if(c[i].a!=0) flag=0;
        }
        for(i=1;i<=m;i++){
            scanf("%d",&p[i]);
            mx=max(mx,p[i]);
        }
        if(flag==1){
            int t=0;
            for(i=1;i<=n;i++){
                if(c[i].v<=v) continue;
                if(c[i].d<=mx) t++;
            }
            if(t!=0) printf("%d %d\n",t,m-1);
            else printf("%d %d\n",t,m);
        }
    }
    return 0;
}
